package com.zjeav.lingjiao.base.comon;

import com.zjeav.lingjiao.base.response.AccessToken;

import okhttp3.ResponseBody;

public class CommonPersenter implements CommonModel.OnDownLoadListener, CommonModel.OnAccessTokenListener {
    CommonModel model;
    CommonView.View view;

    public CommonPersenter(CommonView.View view) {
        this.view = view;
        this.model = new CommonModel();
    }

    public void downLoad(String url, int type) {
        this.model.downLoad(url, type, this);
    }

    public void getAccessToken(String appid, String secret, String code, String grant_type) {
        this.model.getToken(appid, secret, code, grant_type, this);
    }

    @Override
    public void OnDownLoadSuccess(ResponseBody body, int type) {
        this.view.getLoadResult(body, type);
    }

    @Override
    public void OnDownLoadFailure(Throwable throwable) {
        this.view.showError(throwable);
    }

    @Override
    public void OnGetTokenSuccess(AccessToken token) {
        this.view.getAccessToken(token);
    }

    @Override
    public void OnGetTokenFail(Throwable throwable) {
        this.view.showError(throwable);
    }
}
